/**
 * 
 */
package jmine.tec.di.injector.impl;

import java.util.ArrayList;
import java.util.List;

import jmine.tec.annotations.Unmodifiable;
import jmine.tec.di.injector.DependencyInjector;
import jmine.tec.di.injector.Injector;
import jmine.tec.di.scope.TypedScope;

import org.springframework.beans.factory.config.AutowireCapableBeanFactory;

/**
 * Injects using a bean definition from the beanFactory
 * 
 * @author takeshi
 */
@Unmodifiable
public class BeanDefinitionConfigurerInjector implements DependencyInjector {

    private final AutowireCapableBeanFactory beanFactory;

    private final String beanDefinitionName;

    /**
     * C'tor
     * 
     * @param beanFactory the {@link AutowireCapableBeanFactory}
     * @param beanDefinitionName the bean definition name
     */
    public BeanDefinitionConfigurerInjector(final AutowireCapableBeanFactory beanFactory, final String beanDefinitionName) {
        super();
        this.beanFactory = beanFactory;
        this.beanDefinitionName = beanDefinitionName;
    }

    /**
     * {@inheritDoc}
     */
    public Injector[] getAllInjectors() {
        return new Injector[0];
    }

    /**
     * {@inheritDoc}
     */
    public void inject(Object target, TypedScope properties) {
        this.beanFactory.configureBean(target, this.beanDefinitionName);
    }

    /**
     * {@inheritDoc}
     */
    public List<String> validateRequiredProperties(TypedScope scope) {
        return new ArrayList<String>();
    }

}
